<?php

function VoteDataCenter_pntables()
{
    // Initialise table array
    $pntable = array();
    

    ////////////////////////////////////////////
    //Region table
    ////////////////////////////////////////////
    $pntable['votedatacenter_region'] = DBUtil::getLimitedTablename('votedatacenter_region');
    $pntable['votedatacenter_region_column'] = array(
                                        'id'                => 'region_id',
                                        'name'              => 'region_name',
                                        'latitude'          => 'region_latitude',
                                        'longitude'         => 'region_longitude'
    );
    $pntable['votedatacenter_region_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'code'              => 'INT(11) NOTNULL',
                                        'name'              => 'varchar(255)',
                                        'latitude'          => 'varchar(255)',
                                        'longitude'         => 'varchar(255)'
    );
    $pntable['votedatacenter_region_primary_key_column'] = 'id';
    
    ////////////////////////////////////////////
    //Province table
    ////////////////////////////////////////////
    $pntable['votedatacenter_province'] = DBUtil::getLimitedTablename('votedatacenter_province');
    $pntable['votedatacenter_province_column'] = array(
                                        'id'                => 'province_id',
                                        'region_id'         => 'province_region_id',
                                        'code'              => 'province_code',
                                        'name'              => 'province_name',
                                        'latitude'          => 'province_latitude',
                                        'longitude'         => 'province_longitude'
    );
    $pntable['votedatacenter_province_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'region_id'         => 'INT(11) NOTNULL',
                                        'code'              => 'INT(11) NOTNULL',
                                        'name'              => 'varchar(255)',
                                        'latitude'          => 'varchar(255)',
                                        'longitude'         => 'varchar(255)'
    );
    $pntable['votedatacenter_province_primary_key_column'] = 'id';

    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['votedatacenter_province_column'], 'province_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votedatacenter_province_column_def']);
    
    //set table key
    $pntable['votedatacenter_province_column_idx'] = array(
                                                					 'idx_province_region_id' => 'region_id',  
																											     'idx_province_code'      => 'code'	     
																										 );

    ////////////////////////////////////////////
    //District table
    ////////////////////////////////////////////
    $pntable['votedatacenter_district'] = DBUtil::getLimitedTablename('votedatacenter_district');
    $pntable['votedatacenter_district_column'] = array(
                                        'id'                => 'district_id',
                                        'region_id'         => 'district_region_id',
                                        'province_code'     => 'district_province_code',
                                        'code'              => 'district_code',
                                        'name'              => 'district_name',
                                        'latitude'          => 'district_latitude',
                                        'longitude'         => 'district_longitude'
    );
    $pntable['votedatacenter_district_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                   			'region_id'         => 'INT(11) NOTNULL',
                                        'province_code'     => 'INT(11) NOTNULL',
                                        'code'              => 'INT(11) NOTNULL',
                                        'name'              => 'varchar(255)',
                                        'latitude'          => 'varchar(255)',
                                        'longitude'         => 'varchar(255)'
    );
    $pntable['votedatacenter_district_primary_key_column'] = 'id';

    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['votedatacenter_district_column'], 'district_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votedatacenter_district_column_def']);

    //set table key
    $pntable['votedatacenter_district_column_idx'] = array(
                                            							 'idx_district_region_id'     => 'region_id',
    																											 'idx_district_province_code' => 'province_code',
    																											 'idx_district_code'          => 'code'    		
    																								 );

    ////////////////////////////////////////////
    //Tambon table
    ////////////////////////////////////////////
    $pntable['votedatacenter_tambon'] = DBUtil::getLimitedTablename('votedatacenter_tambon');
    $pntable['votedatacenter_tambon_column'] = array(
                                        'id'                => 'tambon_id',
                                        'region_id'         => 'tambon_region_id',
                                        'province_code'     => 'tambon_province_code',
                                        'district_code'     => 'tambon_district_code',
                                        'code'              => 'tambon_code',
                                        'name'              => 'tambon_name',
                                        'latitude'          => 'tambon_latitude',
                                        'longitude'         => 'tambon_longitude'
    );
    $pntable['votedatacenter_tambon_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                   			'region_id'         => 'INT(11) NOTNULL',
                                        'province_code'     => 'INT(11) NOTNULL',   
                                        'district_code'     => 'INT(11) NOTNULL', 
                                        'code'              => 'INT(11) NOTNULL',
                                        'name'              => 'varchar(255)',
                                        'latitude'          => 'varchar(255)',
                                        'longitude'         => 'varchar(255)'
    );
    $pntable['votedatacenter_tambon_primary_key_column'] = 'id';
    
    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['votedatacenter_tambon_column'], 'tambon_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votedatacenter_tambon_column_def']);

    //set table key
    $pntable['votedatacenter_tambon_column_idx'] = array(
                                            						 'idx_tambon_region_id'     => 'region_id', 
                                            						 'idx_tambon_province_code' => 'province_code',
    																										 'idx_tambon_district_code' => 'district_code',
    																										 'idx_tambon_code'          => 'code'
    																							 );

    ////////////////////////////////////////////
    //Village table
    ////////////////////////////////////////////
    $pntable['votedatacenter_village'] = DBUtil::getLimitedTablename('votedatacenter_village');
    $pntable['votedatacenter_village_column'] = array(
                                        'id'                => 'village_id',
                                        'region_id'         => 'village_region_id',
                                        'province_code'     => 'village_province_code',
                                        'district_code'     => 'village_district_code',
                                        'tambon_code'       => 'village_tambon_code',
                                        'code'              => 'village_code',
                                        'moo'               => 'village_moo',
                                        'name'              => 'village_name',
                                        'latitude'          => 'village_latitude',
                                        'longitude'         => 'village_longitude'
    );
    $pntable['votedatacenter_village_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                   			'region_id'         => 'INT(11) NOTNULL',
                                        'province_code'     => 'INT(11) NOTNULL',
                                        'district_code'     => 'INT(11) NOTNULL', 
                                        'tambon_code'       => 'INT(11) NOTNULL',
                                        'code'              => 'INT(11) NOTNULL', 
                                        'moo'               => 'INT(11) NOTNULL',
                                        'name'              => 'varchar(255)',
                                        'latitude'          => 'varchar(255)',
                                        'longitude'         => 'varchar(255)'
    );
    $pntable['votedatacenter_village_primary_key_column'] = 'id';
    
    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['votedatacenter_village_column'], 'village_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votedatacenter_village_column_def']);

    //set table key
    $pntable['votedatacenter_village_column_idx'] = array(
                                            						 'idx_village_region_id'      => 'region_id',     
																										     'idx_village_province_code'  => 'province_code',
    																										 'idx_village_district_code'  => 'district_code',
    																										 'idx_village_tambon_code'    => 'tambon_code',
    																										 'idx_village_code'           => 'code',
    																										 'idx_village_moo'            => 'moo'
    																								 );

    ////////////////////////////////////////////
    //House_no table
    ////////////////////////////////////////////
    $pntable['votedatacenter_house_no'] = DBUtil::getLimitedTablename('votedatacenter_house_no');
    $pntable['votedatacenter_house_no_column'] = array(
                                        'id'                => 'house_no_id',
                                        'region_id'         => 'house_no_region_id',
                                        'province_code'     => 'house_no_province_code',
                                        'district_code'     => 'house_no_district_code',
                                        'tambon_code'       => 'house_no_tambon_code',
                                        'village_code'      => 'house_no_village_code',
                                        'name'              => 'house_no_name',
                                        'latitude'          => 'house_no_latitude',
                                        'longitude'         => 'house_no_longitude'
    );
    $pntable['votedatacenter_house_no_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                   			'region_id'         => 'INT(11) NOTNULL',
                                        'province_code'     => 'INT(11) NOTNULL',   
                                        'district_code'     => 'INT(11) NOTNULL', 
                                        'tambon_code'       => 'INT(11) NOTNULL',
                                        'village_code'      => 'INT(11) NOTNULL', 
                                        'name'              => 'varchar(255)',
                                        'latitude'          => 'varchar(255)',
                                        'longitude'         => 'varchar(255)'
    );
    $pntable['votedatacenter_house_no_primary_key_column'] = 'id';
    
    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['votedatacenter_house_no_column'], 'house_no_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votedatacenter_house_no_column_def']);

    //set table key
    $pntable['votedatacenter_house_no_column_idx'] = array(
                                            						 'idx_house_no_region_id'      => 'region_id',     
																										     'idx_house_no_province_code'  => 'province_code',
    																										 'idx_house_no_district_code'  => 'district_code',
    																										 'idx_house_no_tambon_code'    => 'tambon_code',
    																										 'idx_house_no_village_code'   => 'village_code'
    																								 );


    ////////////////////////////////////////////
    //Person table
    ////////////////////////////////////////////
    $pntable['votedatacenter_person'] = DBUtil::getLimitedTablename('votedatacenter_person');
    $pntable['votedatacenter_person_column'] = array(
                                        'id'                => 'person_id',
                                        'region_id'         => 'person_region_id',                                                                                
                                        'province_code'     => 'person_province_code',
                                        'district_code'     => 'person_district_code',
                                        'tambon_code'       => 'person_tambon_code',
                                        'village_code'      => 'person_village_code',
                                        'house_no_id'       => 'person_house_no_id',  
                                        'prefixname'        => 'person_prefixname',                                                                              
                                        'pid'               => 'person_pid',
                                        'firstname'         => 'person_firstname',
                                        'lastname'          => 'person_lastname',
                                        'gender'            => 'person_gender'
    );
    $pntable['votedatacenter_person_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                   			'region_id'         => 'INT(11) NOTNULL',                                        
                                        'province_code'     => 'INT(11) NOTNULL',   
                                        'district_code'     => 'INT(11) NOTNULL', 
                                        'tambon_code'       => 'INT(11) NOTNULL',                                         
                                        'village_code'      => 'INT(11) NOTNULL', 
                                        'house_no_id'       => 'INT(11) NOTNULL', 
                                        'pid'               => 'INT(50)',
                                        'prefixname'        => 'varchar(50)',
                                        'firstname'         => 'varchar(255)',
                                        'lastname'          => 'varchar(255)',
                                        'gender'            => 'varchar(20)'
    );
    $pntable['votedatacenter_person_primary_key_column'] = 'id';
    
    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['votedatacenter_person_column'], 'person_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votedatacenter_person_column_def']);

    //set table key
    $pntable['votedatacenter_person_column_idx'] = array(
                                            						 'idx_person_region_id'      => 'region_id',     
																										     'idx_person_province_code'  => 'province_code',
    																										 'idx_person_district_code'  => 'district_code',
    																										 'idx_person_tambon_code'    => 'tambon_code',    																										 
    																										 'idx_person_village_code'   => 'village_code',
									                                       'idx_person_house_no_id'    => 'house_no_id',
									                                       'idx_person_pid'            => 'pid'       
    																								 );

    ////////////////////////////////////////////
    //Files table
    ////////////////////////////////////////////
    $pntable['votedatacenter_files'] = DBUtil::getLimitedTablename('votedatacenter_files');
    $pntable['votedatacenter_files_column'] = array(
                                        'id'                => 'file_id',
                                        'name'              => 'file_name',
                                        'size'              => 'file_size',
                                        'status'            => 'file_status'
    );
    $pntable['votedatacenter_files_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'name'              => 'varchar(255)',
                                        'size'              => 'varchar(255)',
                                        'status'            => 'INT(11) NOTNULL DEFALT 1'
    );
    $pntable['votedatacenter_files_primary_key_column'] = 'id';
    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['votedatacenter_files_column'], 'file_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votedatacenter_files_column_def']);

    ////////////////////////////////////////////
    //Fail migrate table
    ////////////////////////////////////////////
    $pntable['votedatacenter_migrate_fail'] = DBUtil::getLimitedTablename('votedatacenter_migrate_fail');
    $pntable['votedatacenter_migrate_fail_column'] = array(
                                        'id'                => 'fail_id',
                                        'region'            => 'fail_region',
                                        'province'          => 'fail_province',
                                        'district'          => 'fail_district',
                                        'tambon'            => 'fail_tambon',
                                        'village'           => 'fail_village',
                                        'house_no'          => 'fail_house_no',
                                        'prefixname'        => 'fail_prefixname',
                                        'pid'               => 'fail_pid',
                                        'firstname'         => 'fail_firstname',
                                        'lastname'          => 'fail_lastname',
                                        'gender'            => 'fail_gender',
                                        'failfield'         => 'fail_failfield'
    );
    $pntable['votedatacenter_migrate_fail_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'region'            => 'varchar(255)',
                                        'province'          => 'varchar(255)',
                                        'district'          => 'varchar(255)',
                                        'tambon'            => 'varchar(255)',
                                        'village'           => 'varchar(255)',
                                        'house_no'          => 'varchar(255)',
                                        'pid'               => 'INT(50)',
                                        'prefixname'        => 'varchar(50)',
                                        'firstname'         => 'varchar(255)',
                                        'lastname'          => 'varchar(255)',
                                        'gender'            => 'varchar(20)',
                                        'failfield'         => 'TEXT'
    );
    $pntable['votedatacenter_migrate_fail_primary_key_column'] = 'id';
    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['votedatacenter_migrate_fail_column'], 'fail_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votedatacenter_migrate_fail_column_def']);

    //set table key
    $pntable['votedatacenter_migrate_fail_column_idx'] = array(
                                        'idx_fail_pid'            => 'pid'
                                        );

    ////////////////////////////////////////////
    //XML Update table
    ////////////////////////////////////////////
    $pntable['votedatacenter_xml_update'] = DBUtil::getLimitedTablename('votedatacenter_xml_update');
    $pntable['votedatacenter_xml_update_column'] = array(
                                        'id'                => 'xmlu_id',
                                        'layer'             => 'xmlu_layer',
                                        'updatetime'        => 'xmlu_updatetime'
    );
    $pntable['votedatacenter_xml_update_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'layer'             => 'VARCHAR(255)',
                                        'updatetime'        => 'DATETIME NULL'
    );
    $pntable['votedatacenter_xml_update_primary_key_column'] = 'id';

    return $pntable;
}